package com.acmedcare.framework.plugin.sample;

import com.acmedcare.framework.exchange.center.core.metadata.IDataApplication;
import com.acmedcare.framework.exchange.center.core.metadata.PluginEntityScan;
import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;

@Slf4j
@PluginEntityScan
@MapperScan({"com.acmedcare.framework.plugin.sample.repository"})
@SpringBootApplication(scanBasePackageClasses = {Application.class})
public class Application implements IDataApplication {

  public static ConfigurableApplicationContext configurableApplicationContext;


  @Override
  public void load(ClassLoader classLoader) {
    try {
      //  configurableApplicationContext = SpringApplication.run(Application.class);
    } catch (Exception e) {
      log.error("plugin load error", e);
    }
  }


  public static void main(String[] args) throws IOException {
    // new application
    configurableApplicationContext = new SpringApplicationBuilder()
        .sources(Application.class)

        // default properties
        .properties("--spring.profiles.active=default,production")
        .web(WebApplicationType.NONE)
        .run(args);
  }

  @Override
  public void doWork() {

  }

  @Override
  public void close() {

    try {
      configurableApplicationContext.stop();
    } catch (Exception e) {
      log.error("");
    }
  }

  @Override
  public void configChangeNotify(String name, String value) {

  }
}